﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_Logger.h".
//-------------------------------------------------------------------

#ifndef _UXS_VS_CONSOLE_OUTPUT_H
#define _UXS_VS_CONSOLE_OUTPUT_H

#pragma once

#include "ILogger.h"

#ifdef COMPILER_MSVC

namespace UX_STL
{
namespace UXLogger
{

	//
	// Visual Studio Console Output
	//

	class CVSConsoleOutput : public ILogOutput
	{
	public:
		// ILogOutput //
		virtual void Write(const char *pMsg, e_log_msg::type eType, const char *pSrcFile, uint uLine);
		virtual e_log_output::bits	GetTypeBits() const;
		virtual void NewLine();
		virtual void Free();
	};


	
	inline void CVSConsoleOutput::Write(const char *pMsg, e_log_msg::type eType, const char *pSrcFile, uint uLine)
	{
		string	str;
		
		if ( EnumCmp( eType, e_log_msg::_LMPX_TIME ) )
		{
			TPlatform::GetDate( str, e_date::TIME_MSEC );
			str << " - ";
		}

		switch ( eType )
		{
			case e_log_msg::_LMP_INFO	 :
			case e_log_msg::_LMP_NONE	 :		break;
			case e_log_msg::_LMP_WARNING :		str << "WARNING: ";	break;
			case e_log_msg::_LMP_ERROR	 :		str << "ERROR: ";	break;
			case e_log_msg::_LMP_FATAL	 :		str << "FATAL: ";	break;
			case e_log_msg::_LMP_DEBUG	 :		str << "DEBUG: ";	break;
			case e_log_msg::_LMP_SYSTEM	 :		str << "SYSTEM: ";	break;
			case e_log_msg::_LMP_USER	 :		str << "USER: ";	break;
		}

		str << pMsg;
		
		if ( EnumCmp( eType, e_log_msg::_LMPX_FILE_LINE ) and pSrcFile != null and uLine != -1 )
			str << "( file: \"" << pSrcFile << "\", line: " << uLine << ')';

		str << "\n";

		winapi::OutputDebugString( str.cstr() );
	}


	inline void CVSConsoleOutput::NewLine()
	{
		winapi::OutputDebugString( "\n" );
	}
	

	inline void CVSConsoleOutput::Free()
	{
		delete this;
	}
	

	inline e_log_output::bits CVSConsoleOutput::GetTypeBits() const
	{
		return e_log_output::IDE_CONSOLE_BIT;
	}
	
//-------------------------------------------------------------------

}	// UXLogger
}	// UX_STL

#endif	// COMPILER_MSVC
#endif	// _UXS_VS_CONSOLE_OUTPUT_H